package com.jinlejia.feedback.idea.ui.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.jinlejia.feedback.R;

import java.util.List;

/**
 * @author SongJiaTai
 * @description:
 * @date :2019/7/1 14:49
 */
public class FBTimeDropDownAdapter extends BaseAdapter{
    private Context context;
    private List<String> list;
    public String startTime;
    public String endTime;
    private static int type;
    private int checkItemPosition = 0;

    public void setCheckItem(int position) {
        checkItemPosition = position;
        notifyDataSetChanged();
    }

    public FBTimeDropDownAdapter(Context context, List<String> list) {
        this.context = context;
        this.list = list;
    }

    public FBTimeDropDownAdapter(Context context, List<String> list, int type) {
        this.context = context;
        this.list = list;
        this.type = type;
    }

    public FBTimeDropDownAdapter(Context context, List<String> list, String startTime , String endTime) {
        this.context = context;
        this.list = list;
        this.startTime = startTime;
        this.endTime = endTime;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView != null) {
            viewHolder = (ViewHolder) convertView.getTag();
        } else {
            convertView = LayoutInflater.from(context).inflate(R.layout.fb_item_time_down, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }
        fillValue(position, viewHolder);
        return convertView;
    }

    private void fillValue(int position, ViewHolder viewHolder) {
        viewHolder.text.setText(list.get(position));
        if( list.get(position).equals("最早日期") ){
            viewHolder.timeText.setText( startTime );
        }else{
            viewHolder.timeText.setText( endTime );
        }
        if (checkItemPosition != -1) {
            if (checkItemPosition == position) {
                viewHolder.text.setTextColor(Color.parseColor("#F0BA00"));
            } else {
                viewHolder.text.setTextColor(Color.parseColor("#999999"));
            }

        }
    }

    static class ViewHolder {
        TextView text;
        TextView timeText;
        ViewHolder(View view) {
            text = view.findViewById(R.id.text);
            timeText = view.findViewById(R.id.time_text);
        }
    }


}
